package edu.columbia.aicheckers.model;


/**
 * This class represents the qualities associated with a move
 * including current position, detination, etc.
 * @author C.M.R
 *
 */
public class Move 
{

	private int destination;
	private Checker checker;
	private Checker skippedChecker;
	private int utility;
	
	
	public Move(Checker checker, int i) {
		this.checker = checker;
		this.destination = i;
	}
	
	/**
	 * Constructor to create a move
	 * @param checker the Checker to move
	 * @param i 
	 * @param skippedChecker
	 */
	public Move(Checker checker, int i, Checker skippedChecker) {
		this(checker,i);
		this.skippedChecker = skippedChecker;
	}

	public void setCheckerPiece(Checker checker)
	{
		this.checker = checker;
	}
	
	public void setDestination(int dest)
	{
		this.destination = dest;
	}
	
	public Checker getCheckerPiece()
	{
		return checker;
	}
	
	public int getDestination()
	{
		return destination;
	}

	public int getSkippedLocation() {
		if(skippedChecker == null)
		{
			throw new IllegalArgumentException("Use hasSkip to check if Move has a skipped checker");
		}
		else
		{
			return skippedChecker.getLocation();
		}
	}
	
	public boolean makeNewKing()
	{
		if(checker.isKing())
		{
			return false;
		}
		if(checker.getColor() == Color.White)
		{
			if(destination <= 4)
			{
				return true;
			}
			return false;
		}
		else if(checker.getColor() == Color.Black)
		{
			if(destination >= 29)
			{
				return true;
			}
			return false;
		}
		throw new RuntimeException("Code should not get here - it would be an invalid move");
	}

	public boolean hasSkip() {
		return skippedChecker != null;
	}
	
	@Override
	public int hashCode()
	{
		int hashCode = destination;
		if(checker != null)
			hashCode += checker.hashCode();
		if(skippedChecker != null)
			hashCode += skippedChecker.hashCode();
		return hashCode;
	}
	
	@Override
	public boolean equals(Object o)
	{
		if(o instanceof Move)
		{
			Move m = ((Move)o);
			if(m.checker == checker &&
			m.destination == destination &&
			m.skippedChecker == skippedChecker)
				return true;
			
		}
		return false;	
	}
	
	@Override
	public String toString()
	{
		return "(" + checker.getLocation() + "," + destination + ")";
	}
	
	
}
